define(function(require){
	var $=require("jq");
	var Dialog=require("pz_use_dialog.js");
	
	$.fn.checkCode = function(){
		if($(this).val()==""){
			$(this).next().html("请输入手机验证码！").show().removeClass("ok").addClass("tips");
			return false;
		}else{
			$(this).next().html("").show().removeClass("tips").addClass("ok");
			return true;
		}
	}
	
	$('#submit').on('click',function(event){
		var mobile = $('#mobile').val();
		var code = $('#code').val();
		if(!$('#code').checkCode()){
			return;
		}
		var action = $('#action').val();
		var params = {};
		params['mobile'] = mobile;
		params['code'] = code;
		params['action'] = action;
		$.post("/vipCenter/identityCheckOK.do",params,function(data){
			var result = eval("("+data+")");
			if(result['ok'] == 1){
				window.location.href=result['url'];
				return;
			}else if(result['ok'] == 0){
				$('#code').val('').next().html(result['msg']).show().removeClass("ok").addClass("tips");
				return;
			}
		});
	});
	
	//倒计时发送验证码开始
	var time = 60;
	var t;
	var inputBtn = $("#getCode");
	
	inputBtn.on("click",function(){
		var mobile = $('#mobile').val();
		var params = {};
		params['mobile'] = mobile;
		$.getJSON("/vipCenter/identityCheck/getCode.do",params,function(data){
  			if(data['ok']){
  				timer();
  				$('#code').removeAttr('readonly').removeClass();
  			}else{
  				alert('获取验证码失败');
  				return;
  			}
  		},"json");
	});
	
	function timer(){
		var t = window.setTimeout(function(){
				if(time==0){
					clearTimeout(t);
					inputBtn.val("重新获取验证码");
					inputBtn.attr("disabled",false);
					time= 60;
					return;
				}
				inputBtn.val(time+"秒后重新获取");
				inputBtn.attr("disabled",true);
				time--;
				timer();
		},1000);
	}
});